﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SM2Utilities;
using SM2Profile;
using ArtOfTest.WebAii.Controls.HtmlControls;

namespace SM2ReportsData
{
    public class GenerateReport
    {
        public static void GenerateReportDashboard(string strProfile, string strDashboardName)
        {
            //Load Reports
            CommonLoader.load("home.aspx");
            ProfileActions.loadProfile(strProfile);
            CommonLoader.load("reports.aspx");

            //Select DashBoard            
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            HtmlTable cphPageContent_Wizard1 = UpdatePanel1.Find.ById<HtmlTable>("cphPageContent_Wizard1");
            HtmlDiv cphPageContent_Wizard1_pnlReportsBlogosphere = cphPageContent_Wizard1.Find.ById<HtmlDiv>("cphPageContent_Wizard1_pnlReportsBlogosphere");
            HtmlInputRadioButton cphPageContent_Wizard1_rbDashboard = cphPageContent_Wizard1_pnlReportsBlogosphere.Find.ById<HtmlInputRadioButton>("cphPageContent_Wizard1_rbDashboard");
            SM2Input.Tradition.SelectRadio(cphPageContent_Wizard1_rbDashboard);

            //Hit Next button
            GenerateReportActions.ClikOnButton("Next >>");

            //Select DB
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            cphPageContent_Wizard1 = UpdatePanel1.Find.ById<HtmlTable>("cphPageContent_Wizard1");
            HtmlDiv cphPageContent_Wizard1_pnlDashboardsScroller = cphPageContent_Wizard1.Find.ById<HtmlDiv>("cphPageContent_Wizard1_pnlDashboardsScroller");
            HtmlTable cphPageContent_Wizard1_grdDashboards = cphPageContent_Wizard1_pnlDashboardsScroller.Find.ById<HtmlTable>("cphPageContent_Wizard1_grdDashboards");

            int intCountRows_Jobs = cphPageContent_Wizard1_grdDashboards.AllRows.Count;
            for (int i = 1; i < intCountRows_Jobs; i++)
            {
                HtmlTableRow tblrow = cphPageContent_Wizard1_grdDashboards.AllRows[i];
                HtmlTableCell tblCellDBName = tblrow.Cells[1];

                string str_tblCellDBName = tblCellDBName.TextContent;

                if (str_tblCellDBName.Contains(strDashboardName))
                {
                    HtmlTableCell tblCellDB_Radio = tblrow.Cells[0];
                    IList<HtmlInputRadioButton> iList_Radio = tblCellDB_Radio.Find.AllByAttributes<HtmlInputRadioButton>();
                    HtmlInputRadioButton radioDB = iList_Radio[0];
                    SM2Input.Tradition.SelectRadio(radioDB);
                    break;
                }
            }

            //Hit Next button
            GenerateReportActions.ClikOnButton("Next >>");

            //Choose Email Once
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            UpdatePanel1 = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("UpdatePanel1");
            cphPageContent_Wizard1 = UpdatePanel1.Find.ById<HtmlTable>("cphPageContent_Wizard1");
            HtmlDiv cphPageContent_Wizard1_pnlUpdateSchedule = cphPageContent_Wizard1.Find.ById<HtmlDiv>("cphPageContent_Wizard1_pnlUpdateSchedule");
            HtmlInputRadioButton cphPageContent_Wizard1_stpSchedule_rbRunNow = cphPageContent_Wizard1_pnlUpdateSchedule.Find.ById<HtmlInputRadioButton>("cphPageContent_Wizard1_stpSchedule_rbRunNow");
            SM2Input.Tradition.SelectRadio(cphPageContent_Wizard1_stpSchedule_rbRunNow);

            //Hit Next button
            GenerateReportActions.ClikOnButton("Next >>");

            //Hit Finish button
            GenerateReportActions.ClikOnButton("Finish");
        }
    }
}
